package com.kevin.memo;

/**
 * 备忘录模式
 *
 * @author kevin
 * @date 2025/8/7
 */
public class MementoPattern {

    /**
     * 备忘录类
     */
    class Memento {
        private String state;

        public Memento(String state) {
            this.state = state;
        }

        public void setState(String state) {
            this.state = state;
        }

        public String getState() {
            return state;
        }
    }

    /**
     * 发起人类
     */
    class Originator {

        private String state;

        public void setState(String state) {
            this.state = state;
        }

        public String getState() {
            return state;
        }

        public Memento createMemento() {
            return new Memento(state);
        }

        public void restoreMemento(Memento memento) {
            this.state = memento.getState();
        }
    }

    /**
     * 管理类
     */
    class Caretaker {
        private Memento memento;

        public void setMemento(Memento memento) {
            this.memento = memento;
        }

        public Memento getMemento() {
            return memento;
        }
    }
}
